﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using HCFramework.API.LINQ;

namespace C
{
    public class NewsCategoryController
    {
        public static void Insert(NewsCategory a)
        {
            HCDataContext db = new HCDataContext();
            db.NewsCategories.InsertOnSubmit(a);
            db.SubmitChanges();
        }

        public static void Update(NewsCategory a, HCDataContext db)
        {
            db.SubmitChanges();
        }

        public static void Delete(int id)
        {
            HCDataContext db = new HCDataContext();
            NewsCategory a = db.NewsCategories.Where(
                ik => ik.ID == id).First();
            db.NewsCategories.DeleteOnSubmit(a);
            db.SubmitChanges();
        }

        public static NewsCategory GetByID(int id, HCDataContext db)
        {
            return db.NewsCategories.Where(
                ik => ik.ID == id).FirstOrDefault();
        }

        public static NewsCategory GetByID(int id)
        {
            return GetByID(id, new HCDataContext());
        }

        public static NewsCategory GetByCode(string code, HCDataContext db)
        {
            return db.NewsCategories.Where(
                ik => ik.Code == code).FirstOrDefault();
        }

        public static NewsCategory GetByCode(string code)
        {
            return GetByCode(code, new HCDataContext());
        }
    }
}